package com.jhgsys.internal.sypq.service.impl;

import com.jhgsys.internal.sypq.entity.TaskTestlx;
import com.jhgsys.internal.sypq.mapper.TaskTestlxMapper;
import com.jhgsys.internal.sypq.service.ITaskTestlxService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.system.entity.User;
import org.apache.shiro.SecurityUtils;
import com.jhgsys.internal.common.entity.FebsConstant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 流线实验 Service实现
 *
 * @author ganjun
 * @date 2024-12-11 00:38:15
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TaskTestlxServiceImpl extends ServiceImpl<TaskTestlxMapper, TaskTestlx> implements ITaskTestlxService {

    /**
     * 查询（分页）
     * @author ganjun
     * @date 2024-12-11 00:38:15
     * @param request QueryRequest
     * @param taskTestlx taskTestlx
     * @return IPage<TaskTestlx>
    */
    @Override
    public IPage<TaskTestlx> findTaskTestlxPage(QueryRequest request, TaskTestlx taskTestlx) {
        LambdaQueryWrapper<TaskTestlx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskTestlx::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<TaskTestlx> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author ganjun
     * @date 2024-12-11 00:38:15
     * @param taskTestlx taskTestlx
     * @return List<TaskTestlx>
     */
    @Override
    public List<TaskTestlx> findTaskTestlxList(TaskTestlx taskTestlx) {
	    LambdaQueryWrapper<TaskTestlx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskTestlx::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author ganjun
    * @date 2024-12-11 00:38:15
    * @param id
    * @return TaskTestlx
    */
    @Override
    public TaskTestlx findTaskTestlxById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author ganjun
     * @date 2024-12-11 00:38:15
     * @param taskTestlx taskTestlx
     */
    @Override
    @Transactional
    public boolean createTaskTestlx(TaskTestlx taskTestlx) {
        return this.save(taskTestlx);
    }

    /**
     * 修改
     * @author ganjun
     * @date 2024-12-11 00:38:15
     * @param taskTestlx taskTestlx
     */
    @Override
    @Transactional
    public boolean updateTaskTestlx(TaskTestlx taskTestlx) {
        return this.updateById(taskTestlx);
    }

    /**
     * 逻辑删除
     * @author ganjun
     * @date 2024-12-11 00:38:15
     * @param taskTestlx taskTestlx
     * @param taskTestlxIds taskTestlxIds
     */
    @Override
    @Transactional
    public boolean deleteTaskTestlx(TaskTestlx taskTestlx,String taskTestlxIds) {
        boolean result = false;
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        List<String> list = Arrays.asList(taskTestlxIds.split(StringPool.COMMA));

        taskTestlx.setDeletedBy(user.getUserName());
        taskTestlx.setDeletedTime(new Date());
        taskTestlx.setDeletedFlg(FebsConstant.INVALID);
        int update = this.baseMapper.update(taskTestlx,new LambdaQueryWrapper<TaskTestlx>().in(TaskTestlx::getId,list));
        if (update > 0 ){
            result = true;
        }
        return result;
	}

    /**
    * 物理删除
    * @author ganjun
    * @date 2024-12-11 00:38:15
    * @param taskTestlxIds taskTestlxIds
    */
    @Override
    @Transactional
    public boolean physicallyDeleteTaskTestlx(String taskTestlxIds) {
        List<String> list = Arrays.asList(taskTestlxIds.split(StringPool.COMMA));
        LambdaQueryWrapper<TaskTestlx> wapper = new LambdaQueryWrapper<>();
        wapper.in(TaskTestlx::getId,list);
        return this.remove(wapper);
    }
}
